
import 'package:flutter_downloader/flutter_downloader.dart';

import 'Helper.dart';

class FileLoadProgress {


   FileLoadProgress._internal();

  /// 保存单例
  static FileLoadProgress _singleton = new FileLoadProgress._internal();

  /// 工厂构造函数
  factory FileLoadProgress() => _singleton;

  /// 保存事件订阅者队列，key:事件名(id)，value: 对应事件的订阅者队列
  var eList = new Map<String, ProgressCallback>();




   void  on(String eventName, ProgressCallback f) {
    if(eList==null)
    eList=new Map<String, ProgressCallback>();

    if (eventName == null || f == null) return;
    eList[eventName] =f;
  }

  void off(String eventName) {

     eList.remove(eventName);
  }




   void fire(String id, DownloadTaskStatus status, int? progress) {
    
    if(eList==null)
    return;

    var ee = eList[id];

    if (ee == null) return;
   
      ee(id,progress!);
 
  }


}






